﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DAL;
using BLL;

namespace QLTTTH
{
    public partial class frmThongTinLichThi : DevExpress.XtraEditors.XtraForm
    {
        public frmThongTinLichThi()
        {
            InitializeComponent();
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        public void FillControl(LichThi lt)
        {
            this.loupMaKT.EditValue = lt.MaKyThi;
            this.txtMaLichThi.Text = lt.MaLichThi.ToString();
            this.loupMaPhong.EditValue = lt.MaPhong;
            this.loupMaHV.EditValue = lt.MaHV;
            this.txtGioThi.Text = lt.GioThi;
        }


        public delegate void SendData(LichThi lichthi);

        public SendData sendData;
        private void btnLuu_Click(object sender, EventArgs e)
        {
            if (sendData != null)
            {
                var vResult = new LichThiManager().Validate(LayLichThi());
                if (vResult.Valid)
                {
                    sendData(LayLichThi());
                    DialogResult = DialogResult.OK;
                    this.Close();
                }
                else
                {
                    XtraMessageBox.Show(vResult.ToString(), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        public LichThi LayLichThi()
        {
            LichThi lichthi = new LichThi();
            if (!txtMaLichThi.Text.ToString().Equals(""))
            {
                lichthi.MaLichThi = int.Parse(txtMaLichThi.Text.ToString());
            }
            lichthi.MaKyThi = int.Parse(loupMaKT.EditValue.ToString());
            lichthi.MaHV = int.Parse(loupMaHV.EditValue.ToString());
            lichthi.MaPhong = int.Parse(loupMaPhong.EditValue.ToString());
            lichthi.GioThi = txtGioThi.Text;
            return lichthi;
        }

        private void frmThongTinLichThi_Load(object sender, EventArgs e)
        {
            var dsHV = HocVienManager.LayDanhSachHocVien();
            if (dsHV.Success)
            {
                loupMaHV.Properties.DataSource = dsHV.Result;
                loupMaHV.Properties.ValueMember = "MaHV";
                loupMaHV.Properties.DisplayMember = "HoTen";
            }
            var dsKT = KyThiManager.LayDanhSachKyThi();
            if (dsKT.Success)
            {
                loupMaKT.Properties.DataSource = dsKT.Result;
                loupMaKT.Properties.ValueMember = "MaKyThi";
                loupMaKT.Properties.DisplayMember = "NgayThi";
            }
            var dsMP = PhongHocManager.LayDanhSachPhongHoc();
            if(dsMP.Success)
            {
                loupMaPhong.Properties.DataSource = dsMP.Result;
                loupMaPhong.Properties.ValueMember = "MaPhong";
                loupMaPhong.Properties.DisplayMember = "TenPhong";
            }

        }
    }
}